home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5420 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Where Can I Find Standard C Library S
  5. Date: Fri, 09 Feb 96 01:45:29 GMT
  6. Organization: none
  7. Message-ID: <823830329snz@genesis.demon.co.uk>
  8. References: <4fb8mf$ouo@spanky.pls.ov.com> <4fb90l$ouo@spanky.pls.ov.com> <3119E6D9.60FD@cmt.lpr.mail.carel.fi>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <3119E6D9.60FD@cmt.lpr.mail.carel.fi>
  15.            aril@cmt.lpr.mail.carel.fi "Ari Lukumies" writes:
  16.  
  17. >Fletcher.Glenn@ov.com wrote:
  18. >> 
  19. >> 
  20. >> Whoops! for strcpy:
  21. >> 
  22. >> char *strcpy(char *destination, char *source)
  23. >> {
  24. >>     char *retval;
  25. >> 
  26. >>     retval = destination;
  27. >>     while((*destination++ = *source++) != '\0');
  28. >>     return(retval);
  29. >> }
  30. >>                         Fletcher.Glenn@ov.com
  31. >
  32. >... And you wonder why printf("%s\n", strcpy(tmp, "thingyam")); may not give
  33. > correct 
  34. >results using your strcpy version... Try this for size:
  35. >
  36. >        char *strcpy(char *destination, char *source)
  37. >        {
  38. >                char *retval = destination;
  39. >
  40. >                do
  41. >                        *destination = *source++;
  42. >                while (*destination++ != '\0');
  43. >                return retval;
  44. >        }
  45. >
  46. >This will also copy the nul-terminator. :)
  47.  
  48. If you look more closely you'll see that your version has exactly the
  49. same behaviour as Glenn's, which correctly copies the null character
  50. terminator. However both should be:
  51.  
  52.          char *strcpy(char *destination, const char *source)
  53.  
  54. -- 
  55. -----------------------------------------
  56. Lawrence Kirby | fred@genesis.demon.co.uk
  57. Wilts, England | 70734.126@compuserve.com
  58. -----------------------------------------
  59.